#!/usr/bin/env php
<?php
/**
 * Yii console bootstrap file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */
require(__DIR__ . '/../../../loadEnv.php');
defined('YII_DEBUG') or define('YII_DEBUG', false);

$composerAutoload = [
    __DIR__ . '/../../../framework/yii/autoload.php', // in yii2-dev repo
];
$vendorPath = null;
foreach ($composerAutoload as $autoload) {
    if (file_exists($autoload)) {
        require $autoload;
        $vendorPath = dirname($autoload);
        break;
    }
}


require __DIR__ .'/../../../framework/yii/yiisoft/yii2/Yii.php';

require(__DIR__ . '/../../../common/config/bootstrap.php');

require(__DIR__ . '/../../../common/components/Environment.php');
//$api_config = yii\helpers\ArrayHelper::merge(
//    require(__DIR__ . '/../../../common/config/main.php'),
//    require(__DIR__ . '/config/main.php')
//);
$environment = new Environment(); //creating an object
$environment->setIsWebApp(false);

// $environment->setEnv('dev');
// $environment->setEnv('qa');
// $environment->setEnv('prod');
//$environment->setEnv('uat');

// 根目录下 common/config
$environment->setConfigDir(dirname(__FILE__).'/../../../common/config/'); //setting where to search config files
// 当前目录下 config
$environment->setSearchDir(dirname(__FILE__).'/config/');
/**
 *  确认环境
 *  分别加载 当前目录下的 console.php 和 console-$env.php， 并合并
 *  console-$env 文件加载对应 parama-$env 文件
 */
$local_config = $environment->getConfig();

$api_config = yii\helpers\ArrayHelper::merge(
    require(__DIR__ . '/../../../common/config/main.php'),
    $local_config
);
$application = new yii\console\Application($api_config);
if ($vendorPath !== null) {
    $application->setVendorPath($vendorPath);
}
$exitCode = $application->run();
exit($exitCode);
